package bingo.codeweaver.core.utils;

import java.util.Properties;

/**
 * Mar 8, 2009 12:55:30 AM TypeMapping.java
 * Author:yangdongyu(yangdy@bingosoft.net)
 * ReadMe:
 * ChangeLog:
 */
public class SqlJavaTypeMapping {
	
	private static Properties Sql2JavaTypeMapping = PropertiesHelper.loadProperties("Sql2JavaTypeMapping.xml", SqlJavaTypeMapping.class);
	
	private static Properties Java2SqlTypeMapping = PropertiesHelper.loadProperties("Java2SqlTypeMapping.xml", SqlJavaTypeMapping.class);
	
	private static String defaultJavaType = "String";
	
	private static String defaultSQLType = "VARCHAR2(100)";
	
	public static void setDefaultJavaType(String defaultJavaType) {
		SqlJavaTypeMapping.defaultJavaType = defaultJavaType;
	}

	public static void setDefaultSQLType(String defaultSQLType) {
		SqlJavaTypeMapping.defaultSQLType = defaultSQLType;
	}

	public static void registerTypeMapping(String jdbcType,String javaType){
		Sql2JavaTypeMapping.put(jdbcType, javaType);
	}
	
	public static String getJavaType(String jdbcType){
		return Sql2JavaTypeMapping.getProperty(jdbcType, defaultJavaType);
	}
	
	
	public static String getSQLType(Class<?> javaType){
		String typeName = javaType.getName();
		return Java2SqlTypeMapping.getProperty(typeName, defaultSQLType);
	}
}
